//
//  InterstitialAdManager.m
//  bwt_ad_flutter
//
//  Created by ciba on 2024/8/29.
//

#import "BwtSplashAdManager.h"
#import "BwtSplashAd.h"
#import "BwtAdLogManager.h"

@implementation BwtSplashAdManager

/// 单例
+ (BwtSplashAdManager *)getBwtSplashAdManager {
    static BwtSplashAdManager *bwtSplashAdManager;
    if(!bwtSplashAdManager) {
        bwtSplashAdManager = [[BwtSplashAdManager alloc] init];
        [bwtSplashAdManager initData];
    }
    return bwtSplashAdManager;
}

/// 初始化
- (void)initData {
    if (!_splashAdMap) {
        _splashAdMap = [[NSMutableDictionary alloc] initWithCapacity:0];
    }
}

/// 加载开屏广告
- (void)loadSplashAd:(AdParams*)adParams isRequestIdfa:(bool)isRequestIdfa {
    BwtSplashAd *splashAd = [BwtSplashAd alloc];
    splashAd.adParams = adParams;
    splashAd.isRequestIdfa = isRequestIdfa;
    
    NSString *adId = adParams.adId;
    [_splashAdMap setObject:splashAd forKey:adId];
    
    [[BwtAdLogManager getBwtAdLogManager] log:@"开始加载开屏广告, adId: %@", adParams.adId];
    [splashAd loadSplashAd];
}

/// 释放开屏广告
- (void)releaseAd:(NSString*)adId {
    if (adId) {
        BwtSplashAd *splashAd = _splashAdMap[adId];
        if (splashAd) {
            [_splashAdMap removeObjectForKey:adId];
            [[BwtAdLogManager getBwtAdLogManager] log:@"开屏广告已释放, adId: %@", adId];
        }
    }
}
@end
